//
//  PhotoCollectionViewCell.swift
//  XLWB
//
//  Created by 郭亮 on 16/3/20.
//  Copyright © 2016年 gl. All rights reserved.
//

import UIKit

@objc
protocol PhotoCollectionViewCellDelegate: NSObjectProtocol {
    optional func addPhotoTocollectionViewCell(cell: PhotoCollectionViewCell)
    optional func deletePhotoFromcollectionViewCell(cell: PhotoCollectionViewCell)
}

class PhotoCollectionViewCell: UICollectionViewCell {
    // MARK:-属性
    var delegate: PhotoCollectionViewCellDelegate?
    // MARK:-控件属性
    @IBOutlet weak var photoBtn: UIButton!
    @IBOutlet weak var deleteBtn: UIButton!
    var image: UIImage? {
        didSet{
            if image != nil {
                photoBtn.setBackgroundImage(image, forState: .Normal)
                photoBtn.userInteractionEnabled = false
                deleteBtn.hidden = false
            }else {
                photoBtn.setBackgroundImage(UIImage(named: "compose_pic_add"), forState: .Normal)
                photoBtn.userInteractionEnabled = true
                deleteBtn.hidden = true
            }
        }
    }
    
    // MARK:-事件监听
    @IBAction func addPhotoBtnClick(sender: AnyObject) {
        if delegate?.respondsToSelector("addPhotoTocollectionViewCell:") != nil {
        delegate?.addPhotoTocollectionViewCell!(self)
        }
    }
    @IBAction func deletePhotoBtnClick() {
        if delegate?.respondsToSelector("deletePhotoFromcollectionViewCell:") != nil {
        delegate?.deletePhotoFromcollectionViewCell!(self)
        }
    }
}
